define(function(require){
	var $=require("jq");
	 var Dialog=require("/pinzhiV2.0/js/pz_use_dialog.js");
	
	function SelectAddress(addressWrap){
		var _this_=this;
		//保存省份、城市、区县
		this.province=addressWrap.find("#J_Province");
		this.city=addressWrap.find("#J_City");
		this.county=addressWrap.find("#J_County");
		//初始化事件
		this.province.change(function(){
			if(this.value!=0){
				_this_._getCity(this.value);
			}else{
			_this_.city.empty().append("<option value='0' selected>--选择城市--</option>");
			_this_.county.empty().append("<option value='0' selected>--选择区县--</option>");
			};
		});
		this.city.change(function(){
			if(this.value!=0){
				_this_._getCounty(this.value);
			}else{
				_this_.county.empty().append("<option value='0' selected>--选择区县--</option>");
			};
		});
		
	
	};
	SelectAddress.prototype={
		//获取区县
		_getCounty:function(value){
			var _this = this;
			
			$.post("/erp/customerDocument/region.do",{regionId:value},function(regions){
				_this._createOptions(_this.county,regions,"选择区县");
			},"json");
						
		},
		//获取城市
		_getCity:function(value){
			var _this = this;
			_this._createOptions(_this.county,[],"选择区县");
			$.post("/erp/customerDocument/region.do",{regionId:value},function(regions){
				_this._createOptions(_this.city,regions,"选择城市");
			},"json");
			
			
		},
		//创建列表
		_createOptions:function(selectWrap,optionData,text){
			//情况数据
			selectWrap.empty().append("<option value='0' selected>--"+text+"--</option>");
			//添加数据
			$(optionData).each(function(index, element) {
				selectWrap.append("<option value='"+element.id+"'>"+element.name+"</option>");
			});
		}
	};
	var selectAddress=new SelectAddress($("#J_SelectAddress"));
});